﻿/*
 * @author: wizardc
 */

using UnityEngine;

namespace Dou.BoundingVolumeHierarchy
{
    /// <summary>
    /// BVH 工具类
    /// </summary>
    public static class BVHUtil
    {
        /// <summary>
        /// 获取 Bounds 的表面积
        /// </summary>
        public static float GetSurfaceArea(this Bounds box)
        {
            var x_size = box.max.x - box.min.x;
            var y_size = box.max.y - box.min.y;
            var z_size = box.max.z - box.min.z;
            return 2.0f * ((x_size * y_size) + (x_size * z_size) + (y_size * z_size));
        }
        
        /// <summary>
        /// 判定当前对象是否完全包含 other 对象
        /// </summary>
        public static bool Contains(this Bounds thisBounds, Bounds other)
        {
            var result = true;
            result = result && thisBounds.min.x <= other.min.x;
            result = result && thisBounds.min.y <= other.min.y;
            result = result && thisBounds.min.z <= other.min.z;
            result = result && other.max.x <= thisBounds.max.x;
            result = result && other.max.y <= thisBounds.max.y;
            result = result && other.max.z <= thisBounds.max.z;
            return result;
        }
    }
}
